Creating Your First Macromedia Central Application
Table of Contents
Creating a Simple Central Application
To make the "simplest Central app in history" you create a FLA (app.fla) that turns into app.swf. Install the application using a generic version of installer.swf and product.xml, which basically says "install the app.swf file." For modularity purposes, app.fla includes your code inside app.as. Once you have this application running inside Central you can easily add more features.
Here are the steps:
- To make app.fla, open Macromedia Flash MX 2004 or Macromedia Flash MX Professional 2004 and create a new Flash document.
- Access Publish Settings (File > Publish Settings), select the Formats tab, and uncheck the HTML option. Select the Flash tab, change the Version drop-down list to Flash Player 6, and click OK. (You can leave ActionScript 2.0 selected.)
-
Place the following code into the first frame of this movie (there's no semicolon at the end):
#include "app.as" - From the Components panel, drag a TextArea component to the Stage. Use the Free Transform tool to resize the TextArea. With the TextArea still selected, use the Properties panel to give the component an instance name ta. Save this file as app.fla.
- Create a new ActionScript file using Flash MX Professional 2004 (or just Notepad or a similar text editor). Save the file as app.as, adjacent to app.fla.
-
Type the following code:
onActivate = function(shell, appID, shellID, baseTabIndex, appData) { gShell=shell; var myString=""; myString += "shell=" + shell +newline; myString += "id=" + appID +newline; myString += "shellID=" + shellID +newline; myString += "baseTabIndex=" + baseTabIndex +newline; myString += "appData=" + appData; ta.text = myString; } Central.initApplication(this, this);All you really need to turn a Flash app into a Central app is the
initApplication()method. The first parameter(this)refers to what movie is getting initialized and the second parameter(this)refers to where theonActivate()method (and other handlers) can be found. When Central has fully loaded your application it attempts to trigger theonActivate()method in your movie. Provided you write anonActivate()method it's where you can begin to perform Central features. This example just takes the parameters received and puts them in thetaTextArea instance.Invariably, the one thing you'll always do is save into a variable that first parameter. Even though the example above doesn't use
gShell, it's a reference to the window managing your app and your key to triggering any methods in the Shell object. (That is, you can usegShell.isConnected()to determine the user's connection status.) The first parameter in anyonActivate()method gives applications, pods, and agents a reference to their appropriate host (the shell, Console, or—in the case of agents—the Agent Manager). - Save app.as, return to app.fla, and publish app.swf (press Shift-F12).
-
Place app.swf along with the downloaded files product.xml and installer.swf in a test folder on your server. For example, with the default ColdFusion MX installation I use the following folder:
C:\CFusionMX\wwwroot\myFirstCentral\ -
Run installer.swf (not by double-clicking it) from a web browser pointing to the server—in my case:
http://127.0.0.1:8500/myFirstCentral/installer.swfThe ":8500" is there because I have ColdFusion listening to port 8500.
- Click Install Now. If you don't have Central installed, it'll be installed automatically.
Note: If you have problems with this portion, you can find the completed files in the folder "part1_finished—Creating a Simple Central Application."
This application doesn't do much more than show that it's working
(see Figure 2). The five arguments received include handles on the
application itself and initial values such as the starting tab index.
For now, just realize that any Flash application can become a Central
application by just adding the initApplication() trigger.
Figure 2. Although it's not much to look at, the application is now running inside Central.